package com.herench.bs.handler;

import com.herench.bs.agent.IPersonAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * cleverClinic
 * com.herench.bs.handler
 *
 * @author wangwenkai
 * @date 2017/12/24/15:56
 */
@Component
@Handler(code = "100236" ,name="根据openID查询用户信息")
public class LoadUserInfoByOpenIdHandler extends AbstractMessageHandler {
    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage =null;
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        String openId = requestMessage.getArgsPropertyStringValue("openId");
        Assert.notNull(openId,"openId 不能为空！");
        IPersonAgent personAgent = getCleverClinicContext().getApplicationContext().getBean(IPersonAgent.class);
        Map<String,Object> res = personAgent.loadUserInfoByOpenId(channelCode,openId);
        responseMessage = new ResponseMessage(requestMessage.getId());
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage,res);
        return responseMessage;
    }
}
